version: '3.8'
services:
  rust-ddd-example:
    image: mcr.microsoft.com/devcontainers/rust:0-1-bullseye
    volumes:
      - ..:/workspaces:cached
    security_opt:
      - seccomp:unconfined
    command: /bin/sh -c "while sleep 1000; do :; done && rustup update stable"

  kafka1:
    image: 'bitnami/kafka:latest'
    environment:
      - KAFKA_ENABLE_KRAFT=yes
      - KAFKA_CFG_PROCESS_ROLES=broker,controller
      - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka1:9092
      - KAFKA_CFG_BROKER_ID=1
      - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka1:9093
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_NODE_ID=1
      - KAFKA_KRAFT_CLUSTER_ID=L0ZEQh1yTbGhNNUE7-6wSQ
    volumes:
      - restapp_kafka_volume:/bitnami/kafka
    ports:
      - "9092:9092"
      - "9093:9093"

  kafka-ui:
    image: provectuslabs/kafka-ui:v0.4.0
    ports:
      - "8081:8080"
    environment:
      - KAFKA_CLUSTERS_0_BOOTSTRAP_SERVERS=kafka1:9092
      - KAFKA_CLUSTERS_0_NAME=kraft

  application-db:
    user: root
    container_name: meal_shop_db
    image: postgres:16
    command:
      - "postgres"
      - "-c"
      - "max_connections=50"
      - "-c"
      - "shared_buffers=1GB"
      - "-c"
      - "effective_cache_size=4GB"
      - "-c"
      - "work_mem=16MB"
      - "-c"
      - "maintenance_work_mem=512MB"
      - "-c"
      - "random_page_cost=1.1"
      - "-c"
      - "temp_file_limit=10GB"
      - "-c"
      - "log_min_duration_statement=200ms"
      - "-c"
      - "idle_in_transaction_session_timeout=10s"
      - "-c"
      - "lock_timeout=1s"
      - "-c"
      - "statement_timeout=60s"
      - "-c"
      - "shared_preload_libraries=pg_stat_statements"
      - "-c"
      - "pg_stat_statements.max=10000"
      - "-c"
      - "pg_stat_statements.track=all"
    env_file:
      - .env
    volumes:
      - restapp_postgres_volume:/docker-entrypoint-initdb.d
      - restapp_postgres_volume:/var/lib/postgresql/data
      - restapp_postgres_volume:/db
    ports:
      - "5001:5432"
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U root -d restappdb" ]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 4G

volumes:
  restapp_postgres_volume:
  restapp_pgadmin_volume:
  restapp_exporter_volume:
  restapp_kafka_volume: